package com.example.shuiyinceshi

import android.Manifest
import android.app.Activity
import android.content.pm.PackageManager
import android.content.pm.PathPermission
import androidx.core.app.ActivityCompat

class PermissionUtils {


    // 请求码用于回调
    val REQUEST_EXTERNAL_STORAGE = 1
    val REQUEST_EXTERNAL_STORAGE2 = 2
    /**
     * 检查权限并请求访问所有文件的权限
     * @param activity 当前的Activity
     */
    public fun verifyStoragePermissions( activity: Activity) {
        // 检查权限是否被授予
        var permission=ActivityCompat.checkSelfPermission(activity,Manifest.permission.READ_EXTERNAL_STORAGE)
        if(permission != PackageManager.PERMISSION_GRANTED){
            //我们没有被授予权限，所以我们应该去请求它
            ActivityCompat.requestPermissions(activity, arrayOf(Manifest.permission.READ_EXTERNAL_STORAGE),REQUEST_EXTERNAL_STORAGE)

        }


    }
    public fun verifyStoragePermissions2( activity: Activity) {
        // 检查权限是否被授予

        var permission=ActivityCompat.checkSelfPermission(activity,Manifest.permission.WRITE_EXTERNAL_STORAGE)
        if(permission != PackageManager.PERMISSION_GRANTED){
            //我们没有被授予权限，所以我们应该去请求它
            ActivityCompat.requestPermissions(activity, arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE),REQUEST_EXTERNAL_STORAGE2)

        }


    }







}